Skip to content

refactor: move the hosting core behind ports and adapters - #103

Merged
dmccoystephenson merged 1 commit into
mainfrom
refactor/hosting-core-ports
Nov 21, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
refactor/hosting-core-ports

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

The server's hosting policy was moved out of server.py into src/arcade/hosting/, without changing behaviour:

server.py (HTTP adapter) -> hosting/service.py (wiring) -> hosting/core.py (policy, no I/O)
                                                              -> hosting/ports/* <- adapters
Port Production adapter Test double (tests/hosting_fakes.py)
GameCatalog hosting/adapters/reloading_yaml_catalog.py (was server.RegistryHolder, moved nearly verbatim) FakeCatalog
VersionStore, PlayCounter store.Store, unchanged FakeStore
EventReporter trace_client.TraceClient (vendored, untouched), or hosting/adapters/null_reporter.py when trace is off Recorder
ReleaseNotes remote.Remote, unchanged FakeNotes
  • core.Hosting holds gameForHost, describe, addedOf, authorise, checkVersion, deploy, rollback and played. Expected outcomes are values (Denied, Rejected, Deployed) carrying the same status codes and error text as before; the handler maps them to JSON.
  • server.py keeps HTTP parsing, Content-Length handling, streaming, ranges and ETags. Arcade keeps its attributes (store, reporter, registry, visits, remote, walks, ...), so callers and existing tests are unchanged.
  • hashToken now lives in arcade.hosting; __main__ imports it from there.
  • The README's Development section has the diagram, the port table and how to add a new backend.

How behaviour was held fixed

  • Characterization first: 32 tests (tests/test_hosting_characterization.py) pin error texts, describe fields, host lookup and play counting. They passed on the old code before anything moved.
  • Parity: 2,352 generated requests (upload, rollback, game hosts and aliases, user agents, GET/HEAD, API reads, with and without seeded versions) were run against the base commit and this branch. Status, body, chosen headers, stored state, trace events and log lines: 0 differences.
  • Existing tests: none edited. Full suite: 565 passed / 1 skipped before, 684 passed / 1 skipped after (Python 3.8; the skip is zoneinfo).
  • Contracts: each fake and its production adapter pass the same tests (tests/test_hosting_contracts.py).
  • Architecture: tests/test_hosting_architecture.py fails if model, core or a port imports an adapter, the service, the server, remote or trace_client, or if a port or adapter file holds more than one class. It includes a self-test showing the check can fail.
  • Mutation check: 6 mutants were applied to core.py by hand. 5 were killed; the survivor (a nested-label guard in gameForHost) is equivalent, since a slug can't contain a dot.

Notes

  • Logging reaches the core as a callable rather than a port file; it could be promoted to a Log port later.
  • ports/version_store.py re-exports VERSION_PATTERN, VersionExists and NoSuchVersion from arcade.store, since they are the existing contract.
  • The hall (walks, posters) and file streaming were left for a later pass.

drafted by Claude on behalf of Daniel Stephenson

🤖 Generated with Claude Code

https://claude.ai/code/session_01LYNeuk6eJu4dojpaZi8x82

The server's hosting policy (which game a host names, the /api/games
description, upload and rollback, play counting) was moved out of
server.py into src/arcade/hosting/: a core with no I/O, five ports
(GameCatalog, VersionStore, PlayCounter, EventReporter, ReleaseNotes),
the games.yaml catalog and a null reporter as adapters, and a service
that wires the production ones. server.py stays the HTTP adapter.

No behaviour was changed: 32 characterization tests pinned the old
responses first, and 2,352 generated requests gave identical status,
body, headers, stored state, trace events and log lines on the old and
new code. Contract, core-on-fakes and architecture tests were added.

drafted by Claude on behalf of Daniel Stephenson

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LYNeuk6eJu4dojpaZi8x82
@dmccoystephenson
dmccoystephenson merged commit a35e998 into main Nov 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant